<template>
    <view class="container" :style="themeColor">
        <!-- <tab-bar :tabs="tabs" @clickTab="clickTab" :tabIndex="tabIndex"></tab-bar> -->
        <view class="tab">
            <view class="tab-box">
                <view
                    class="tab-item"
                    @click="clickTab(index)"
                    v-for="(item, index) in tabs"
                    :class="{ current: tabIndex == index, 'right-current': index == 1 }"
                    :key="index">
                    <text>{{ item.title }}</text>
                    <view class="bg"></view>
                </view>
            </view>
            <view class="tab-bg"></view>
        </view>
        <view class="main" :class="tabIndex == 0 ? 'left-main' : 'right-main'">
            <swiper
                v-if="loadOk"
                class="swiper"
                :style="{ height: listHeight }"
                :current="tabIndex"
                @change="swiperChange">
                <swiper-item>
                    <accumulate-list :height="listHeight"></accumulate-list>
                </swiper-item>
                <swiper-item>
                    <accumulate-my-list :height="listHeight"></accumulate-my-list>
                </swiper-item>
            </swiper>
        </view>
    </view>
</template>

<script>
import tabBar from "@/components/common/tab-bar.vue"
import accumulateList from "@/pages_shop/components/accumulate/list.vue"
import accumulateMyList from "@/pages_shop/components/accumulate/my-list.vue"
import { getElementHeight } from "@/uni-sub-base/utils/elementUtil.js"
export default {
    components: {
        tabBar,
        accumulateList,
        accumulateMyList,
    },
    data() {
        return {
            tabIndex: 0,
            tabs: [
                {
                    type: 1,
                    title: "累计活动",
                },
                {
                    type: 2,
                    title: "我的累计",
                },
            ],
            listHeight: "",
            loadOk: false,
        }
    },
    mounted() {
        this.getListHeight()
    },
    methods: {
        getListHeight(element) {
            //获取商品高度
            getElementHeight(this, ".main", (e) => {
                this.listHeight = e - uni.upx2px(24) + "px"
                this.loadOk = true
            })
        },
        swiperChange(e) {
            let tabIndex = e.detail.current
            this.clickTab(tabIndex)
        },
        //tab切换
        clickTab(index) {
            if (this.tabIndex != index) {
                this.tabIndex = index
            }
        },
    },
}
</script>

<style lang="scss">
page {
    background: #fea142;
}
.container {
    padding: 0 12rpx;
    padding-top: 30rpx;
}
.main {
    background: $color-brown-1;
    padding: 24rpx 12rpx 0;
}
.right-main {
    border-top-left-radius: 24rpx;
}
.left-main {
    border-top-right-radius: 24rpx;
}
.tab {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    position: relative;
    display: flex;
    flex: 1;
    z-index: 0;
    .tab-box {
        display: flex;
        flex-direction: row;
        align-items: flex-end;
        flex: 1;
        height: 86rpx;
        perspective: 1000;
        z-index: 1;
    }
    .tab-bg {
        position: absolute;
        width: 96%;
        left: 2%;
        right: 2%;
        bottom: 0;
        z-index: 0;
        height: 76rpx;
        background: rgba(255, 255, 255, 0.7);
        border-radius: 24rpx 24rpx 0 0;
    }
    .tab-item {
        display: flex;
        flex: 1;
        justify-content: center;
        align-items: center;
        height: 76rpx;
        &:first-child {
            border-radius: 24rpx 0 0 0;
        }
        &:last-child {
            border-radius: 0 24rpx 0 0;
        }
        text {
            color: $color-brown-1;
            position: relative;
            z-index: 1;
            font-size: $font-size-30;
        }
    }
    .current {
        height: 86rpx;
        position: relative;
        background: rgba(0, 0, 0, 0);
        text {
            color: #ffeab7;
            font-weight: 700;
        }
        .bg {
            position: absolute;
            left: 0;
            top: 0;
            z-index: 0;
            width: 95%;
            height: 86rpx;
            /* 宽高 */
            background-color: $color-brown-1;
            /* 颜色 */
            // padding: 4rpx 10rpx;
            border-radius: 24rpx 18rpx 0 0;
            /* 设置圆角 */
            transform: perspective(12rpx) rotateX(1deg);
            /* 镜头距离元素表面的位置为8px，x轴为1.1倍y轴为1.3倍，绕x轴旋转5度 */
            transform-origin: 0 0;
            /* bottom left = left bottom = 0 100% 中心点偏移量*/
        }
    }

    .right-current {
        .bg {
            margin-left: 5%;
            border-radius: 18rpx 24rpx 0 0;
            // transform: perspective(5rpx) rotateX(1deg);
            /* 镜头距离元素表面的位置为8px，x轴为1.1倍y轴为1.3倍，绕x轴旋转5度 */
            transform-origin: right 0;
        }
    }
}
</style>
